/*
 * @(#)cn.design.pattern.mediator 2020/4/26/0026
 *
 * Copy Right@ 人人译视界
 */


package cn.design.pattern.mediator;

import java.util.HashMap;

/**
 * <pre>
 * @author tuwei
 *
 * @version 0.9
 *
 * 修改版本: 0.9
 * 修改日期: 2020/4/26/0026
 * 修改人 :  tuwei
 * 修改说明: 初步完成
 * 复审人 ：
 * </pre>
 */
public class ConcreateMediator extends Mediator {
	private HashMap<String, Colleague> colleagueMap;
	private HashMap<String, String> interMap;

	public ConcreateMediator() {
		this.colleagueMap = new HashMap<>();
		this.interMap = new HashMap<>();
	}

	@Override
	void register(String colleagueName, Colleague colleague) {
		colleagueMap.put(colleagueName, colleague);
		if (colleague instanceof Alarm) {
			interMap.put("Alarm", colleagueName);
		}
		else if (colleague instanceof CoffeeMachine) {
			interMap.put("CoffeeMachine", colleagueName);
		}
		else if (colleague instanceof TV) {
			interMap.put("TV", colleagueName);
		}
	}

	@Override
	void getMessage(int stateChange, String colleague) {
		if (colleagueMap.get(colleague) instanceof Alarm) {
			if (stateChange == 0) {
				((CoffeeMachine) (colleagueMap.get(interMap.get("CoffeeMachine")))).startCoffee();
				((TV) (colleagueMap.get(interMap.get("TV")))).startTv();
			}
			else if(stateChange == 1) {
				((TV) (colleagueMap.get(interMap.get("TV")))).stopTv();
			}
		}
	}

	@Override
	void sendMessage() {

	}
}
